﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;

public partial class Control_left : System.Web.UI.UserControl
{
    #region 初始化变量
    Tab_CaseClassBll tab_CaseClassBll = new Tab_CaseClassBll();
    Tab_RawMaterialClassBll tab_RawMaterialClassBll = new Tab_RawMaterialClassBll();
    Tab_NewsBll tab_newBll = new Tab_NewsBll();
    /// <summary>
    /// 装修常识类别ID
    /// </summary>
    int _newsCommonClassID = 1;
    /// <summary>
    /// 分页索引
    /// </summary>
    int _pageIndex = 1;
    /// <summary>
    /// 分页页数
    /// </summary>
    int _pageSize = 10;
    #endregion

    #region 页面加载
    protected void Page_Load(object sender, EventArgs e)
    {
        //绑定方案
        this.bindCaseClassF();
        //绑定材料
        this.bindRawMaterialClass();
        //绑定装修常识文章
        this.bindNewsCommon();
    }
    #endregion

    #region 绑定方案父类别
    private void bindCaseClassF() 
    {
        this.Rep_caseClassF.DataSource = this.tab_CaseClassBll.GetModel();
        this.Rep_caseClassF.DataBind();
    }
    #endregion

    #region 绑定方案父类别触发绑定事件 
    /// <summary>
    /// 绑定方案父类别触发绑定事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Rep_caseClassF_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
        {
            Tab_CaseClass tab_CaseClass =new Tab_CaseClass();
            Repeater rep_caseClass = e.Item.FindControl("Rep_caseClass") as Repeater;
            tab_CaseClass = (Tab_CaseClass)e.Item.DataItem;
            int caseClassFID =tab_CaseClass.caseClassID;
            rep_caseClass.DataSource = this.tab_CaseClassBll.GetModelByFID(caseClassFID);
            rep_caseClass.DataBind();
        }
    }
    #endregion

    #region 绑定材料父类别
    /// <summary>
    /// 绑定材料父类别
    /// </summary>
    private void bindRawMaterialClass() 
    {
        this.Rep_RawMaterialClassF.DataSource = this.tab_RawMaterialClassBll.GetModel();
        this.Rep_RawMaterialClassF.DataBind();
    }    
    #endregion

    #region 绑定材料父类别触发绑定事件 
    /// <summary>
    /// 绑定材料父类别触发绑定事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Rep_RawMaterialClassF_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Tab_RawMaterialClass tab_RawMaterialClass = new Tab_RawMaterialClass();
            Repeater rep_RawMaterialClass = e.Item.FindControl("Rep_RawMaterialClass") as Repeater;
            tab_RawMaterialClass = (Tab_RawMaterialClass)e.Item.DataItem;
            int rawMaterialClassFID = tab_RawMaterialClass.rawMaterialClassID;
            rep_RawMaterialClass.DataSource = this.tab_RawMaterialClassBll.GetModelByFID(rawMaterialClassFID);
            rep_RawMaterialClass.DataBind();
        }
    }
    #endregion

    #region 绑定常识
    /// <summary>
    /// 绑定常识
    /// </summary>
    private void bindNewsCommon() 
    {
        this.rep_NewCommon.DataSource = this.tab_newBll.pageForNews(this._pageIndex, this._pageSize, this._newsCommonClassID);
        this.rep_NewCommon.DataBind();
    }
    #endregion

}
